 
import { EActionCode } from "framework/FSM/Action/ActionCode";
import { ActionBase, ActionBaseOfCreep } from "../ActionBase";

/**
 * 预定Action
 */
export class ActionReserve  extends ActionBaseOfCreep<IActionCMD<"reserve">>
{
    protected updateArgs(action: IActionCMD<"reserve">): EActionCode 
    {
        if(super.updateArgs(action) !== EActionCode.OK)
        {
            return EActionCode.FAILED;
        }
        action.arg.controller = Game.getObjectById(action.arg.controller.id) as StructureController;
        if(!action.arg.controller)
        {
            return EActionCode.FAILED;
        }
        return EActionCode.OK;
    }
    protected _execute(action: IActionCMD<"reserve">): ActionCode 
    {
        if(action.arg.entity.pos.distance(action.arg.controller.pos)>1)
        {
            action.arg.entity.mymoveTo({pos:action.arg.controller.pos,range:1},{});
            return EActionCode.RUNNING
        }
       
        if(!action.arg.controller.reservation ||action.arg.controller.room.isMyResverse())
        {
            action.arg.entity.reserveController(action.arg.controller);
        }
        else
        {
            action.arg.entity.attackController(action.arg.controller);
        }
        
        return EActionCode.RUNNING;
    }
}